package TestAop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

/**
 * Created by wangyg 
 * on 2017/7/26 15:44
 */

@Component
@Aspect
//@Configuration
@EnableAspectJAutoProxy
public class AopAspect {
	@Pointcut("execution(** TestAop.ServiceCore.print*())")
	public void pointCut(){

	}

    @Around("pointCut()")
	public void doAround(ProceedingJoinPoint pjp) {
		StopWatch stopWatch=new StopWatch(pjp.getSignature().getDeclaringTypeName() + "." + pjp.getSignature().getName());
		try {

			stopWatch.start();
			pjp.proceed();
		} catch (Throwable throwable) {
			throwable.printStackTrace();
		}finally {
			stopWatch.stop();
			System.out.println(stopWatch.prettyPrint());
//			System.out.println();

		}
	}
}
